package com.ewei.web.crawler.service;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;

import com.ewei.web.crawler.dao.Queue;
import com.ewei.web.crawler.domain.URLs;
import com.ewei.web.crawler.pool.CrawlerThreadPool;


/**
 * 用jsoup小工具爬取知乎下的问题
 * 信息，存放到mongodb数据库中
 *（由于电脑存储资源有限，默认只爬取每个话题【无论父子话题】下的最新动态）
 */
public class CrawlerService 
{
	/**
	 * 主机地址
	 */
	public static final String REFER = "http://www.zhihu.com";
	/**
	 * 程序主入口
	 * @param args
	 */
    public static void main( String[] args )
    {	
    	execute(REFER+"/topic/19776749");//知乎根话题链接
    }
    private static void execute(String rootUrl){
    	URLs url = new URLs(rootUrl, "知乎根话题");
    	CrawlerLogin login = new CrawlerLogin();
    	Map<String,String> cookies = login.login("13527956557","yihua031211");
    	CrawlerThreadPool pool = CrawlerThreadPool.getInstance();
    	pool.setCookies(cookies);
    	pool.addURL(url);
		pool.start();//开始
//    	pool.addURL(url);
//    	pool.init();//初始化线程池
    }
}
